package com.mall.canal.listener;

import com.mall.goods.feign.SkuFeign;
import com.mall.goods.model.AdItems;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @author Darren
 * @date 2022-08-19 15:59
 * Description：实时同步推广产品缓存
 */
@Component
@CanalTable("ad_items")
public class AdItemsHandler implements EntryHandler<AdItems> {
    @Autowired
    private SkuFeign skuFeign;

    @Override
    public void insert(AdItems adItems) {
        if (adItems.getType() == null)
            return;
        skuFeign.updateTypeSkuItems(adItems.getType());
        System.out.println("adItem canal insert success~");
    }

    @Override
    public void update(AdItems before, AdItems after) {
        if (after.getType() == null || before.getType() == null)
            return;
        // type变更情况
        if (after.getType().intValue() != before.getType().intValue()) {
            skuFeign.updateTypeSkuItems(before.getType());
        }
        // type不变情况
        skuFeign.updateTypeSkuItems(after.getType());
        System.out.println("adItem canal update success~");
    }

    @Override
    public void delete(AdItems adItems) {
        if (adItems.getType() == null)
            return;
        skuFeign.delTypeSkuItems(adItems.getType());
        System.out.println("adItem canal delete success~");
    }

}
